package com.wits.av;

import android.media.MediaCodec;

import java.nio.ByteBuffer;

/**
 * Created by terry on 2016/4/11.
 */
public class MPacket {

    public int type;
    public byte[] data;	/// 数据指针
    public long pts;	/// 时间戳
    public int duration;	/// 时长
    public int flags;		/// 标识

    public MPacket() {

    }

    public MPacket(int type, byte[] data, long pts, int flags) {
        this.type = type;
        this.data = data;
        this.pts = pts;
        this.flags = flags;
        this.duration = 0;
    }

    public MPacket(int type, ByteBuffer buffer, long pts, int flags) {
        this.type = type;

        data = new byte[buffer.remaining()];
        buffer.get(data);

        this.pts = pts;
        this.flags = flags;
        this.duration = 0;
    }

    public byte[] getData() {
        return data;
    }

    public void setData(byte[] data) {
        this.data = data;
    }

    public long getPts() {
        return pts;
    }

    public void setPts(long time) {
        this.pts = time;
    }

    public int getFlags() {
        return flags;
    }

    public void setFlags(int flags) {
        this.flags = flags;
    }

    public  int size() {
        if (data == null) {
            return 0;
        }
        return data.length;
    }

    public int getDuration() {
        return duration;
    }

    public void setDuration(int duration) {
        this.duration = duration;
    }
    
    public boolean isKey() {
        return (flags & MediaCodec.BUFFER_FLAG_KEY_FRAME) == MediaCodec.BUFFER_FLAG_KEY_FRAME;
    }

    public boolean isVideo() {
        return (type == MediaType.MEDIA_TYPE_VIDEO);
    }
}
